<?php
    use User\Model\RecommendModel;
?>
<!-- page heading start-->
<div class="page-heading">
    <h3>
        任务宝活动
    </h3>

</div>
<!-- page heading end-->
<div class="row">
    <div class="col-sm-12">
        <section class="panel">
            <header class="panel-heading">
                <a class="btn btn-default" href="/User/Recommend/add">增加</a>
            </header>
            <div class="panel-body">
                <table class="table table-hover general-table table-bordered">
                    <thead>
                    <tr>
                        <th width="5%">ID</th>
                        <th width="10%">活动名称</th>
                        <th width="12%">公众号</th>
                        <th width="12%">说明</th>
                        <th width="12%">背景图</th>
                        <th width="12%">推广路径</th>
                        <th width="12%">创建时间</th>
                        <th width="7%">状态</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php foreach($list as $val){?>
                    <tr>
                        <td>
                            <span>
                                <?php echo $val['rec_id'];?>
                            </span>
                        </td>
                        <td>
                            <span style="word-break:break-all">
                                <?php echo $val['name'];?>
                            </span>
                        </td>
                        <td>
                            <span style="word-break:break-all">
                                <?php echo $val['wechat_name'];?>
                            </span>
                        </td>
                        <td>
                            <span style="word-break:break-all">
                                <?php echo $val['desc'];?>
                            </span>
                        </td>
                        <td>
                            <span style="word-break:break-all">
                                <img src="<?php echo $val['picurl']?>" style="width: 50px;height: 50px;" alt="">
                            </span>
                        </td>
                        <td>
                            <span style="word-break:break-all">
                                <?php echo $val['url'];?>
                            </span>
                        </td>
                        <td>
                            <span>
                                <?php echo $val['added_date'];?>
                            </span>
                        </td>
                        <td>
                            <span>
                                <?php echo RecommendModel::get_status($val['status']);?>
                            </span>
                        </td>
                        <td>
                            <div>
                                <a class="btn btn-default"
                                   href="<?php echo '/User/Recommend/update?type=update&recId=' . $val['rec_id'];?>">编辑</a>
                                <a class="btn btn-danger" href="#"
                                   onclick="<?php echo 'return delete_data(' . $val['rec_id'] .')';?>">删除</a>
                                <a class="btn btn-success" href="#"
                                   onclick="<?php echo 'return pass_data(' . $val['rec_id'] .')';?>">发布</a>
                            </div>
                            <div style="margin-top: 10px;">
                                <a class="btn btn-warning" href="#"
                                   onclick="<?php echo 'return unpass_data(' . $val['rec_id'] .')';?>">停用</a>
                                <a class="btn btn-info"
                                   href="<?php echo '/User/Recommend/dindex?recId=' . $val['rec_id'];?>">数据统计</a>
                            </div>
                        </td>
                    </tr>
                    <?php }?>

                    </tbody>
                </table>
                <div class="pages">
                    {$page}
                </div>
            </div>
        </section>
    </div>
</div>
<script>
    function delete_data(id){
        $.ajax({
            data:{recId:id},
            dataType:'json',
            url:'/User/Recommend/delete',
            type:'get',
            success:function(res){
                window.location.reload();
            }
        });
        return false;
    }
    function pass_data(id){
        $.ajax({
            data:{recId:id},
            dataType:'json',
            url:'/User/Recommend/pass',
            type:'get',
            success:function(res){
                window.location.reload();
            }
        });
        return false;
    }
    function unpass_data(id){
        $.ajax({
            data:{recId:id},
            dataType:'json',
            url:'/User/Recommend/unpass',
            type:'get',
            success:function(res){
                window.location.reload();
            }
        });
        return false;
    }
</script>